from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-01-03 14:04:09.307045
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 03, Jan, 2022
Time: 14:04:13
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.6749
Nobs: 525.000 HQIC: -48.1195
Log likelihood: 6092.02 FPE: 9.49900e-22
AIC: -48.4057 Det(Omega_mle): 8.01544e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.372043 0.076507 4.863 0.000
L1.Burgenland 0.098594 0.043245 2.280 0.023
L1.Kärnten -0.114159 0.022291 -5.121 0.000
L1.Niederösterreich 0.175208 0.089838 1.950 0.051
L1.Oberösterreich 0.103224 0.089611 1.152 0.249
L1.Salzburg 0.279945 0.046192 6.061 0.000
L1.Steiermark 0.029784 0.060069 0.496 0.620
L1.Tirol 0.110177 0.048479 2.273 0.023
L1.Vorarlberg -0.078095 0.042782 -1.825 0.068
L1.Wien 0.029211 0.080680 0.362 0.717
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.042847 0.168384 0.254 0.799
L1.Burgenland -0.041531 0.095178 -0.436 0.663
L1.Kärnten 0.039700 0.049060 0.809 0.418
L1.Niederösterreich -0.212066 0.197723 -1.073 0.283
L1.Oberösterreich 0.455415 0.197224 2.309 0.021
L1.Salzburg 0.294920 0.101663 2.901 0.004
L1.Steiermark 0.116446 0.132206 0.881 0.378
L1.Tirol 0.307132 0.106696 2.879 0.004
L1.Vorarlberg 0.018687 0.094158 0.198 0.843
L1.Wien -0.012243 0.177569 -0.069 0.945
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.215079 0.038966 5.520 0.000
L1.Burgenland 0.092492 0.022025 4.199 0.000
L1.Kärnten -0.005778 0.011353 -0.509 0.611
L1.Niederösterreich 0.227653 0.045755 4.975 0.000
L1.Oberösterreich 0.160281 0.045640 3.512 0.000
L1.Salzburg 0.038811 0.023526 1.650 0.099
L1.Steiermark 0.028821 0.030594 0.942 0.346
L1.Tirol 0.079245 0.024691 3.210 0.001
L1.Vorarlberg 0.054675 0.021789 2.509 0.012
L1.Wien 0.109948 0.041091 2.676 0.007
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.151417 0.038946 3.888 0.000
L1.Burgenland 0.040062 0.022014 1.820 0.069
L1.Kärnten -0.012951 0.011347 -1.141 0.254
L1.Niederösterreich 0.161438 0.045732 3.530 0.000
L1.Oberösterreich 0.333374 0.045617 7.308 0.000
L1.Salzburg 0.101701 0.023514 4.325 0.000
L1.Steiermark 0.111827 0.030578 3.657 0.000
L1.Tirol 0.089813 0.024678 3.639 0.000
L1.Vorarlberg 0.054180 0.021778 2.488 0.013
L1.Wien -0.031767 0.041071 -0.773 0.439
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.125545 0.073230 1.714 0.086
L1.Burgenland -0.041012 0.041393 -0.991 0.322
L1.Kärnten -0.039956 0.021336 -1.873 0.061
L1.Niederösterreich 0.136823 0.085989 1.591 0.112
L1.Oberösterreich 0.170528 0.085772 1.988 0.047
L1.Salzburg 0.271877 0.044213 6.149 0.000
L1.Steiermark 0.073464 0.057496 1.278 0.201
L1.Tirol 0.139727 0.046402 3.011 0.003
L1.Vorarlberg 0.096732 0.040949 2.362 0.018
L1.Wien 0.069824 0.077224 0.904 0.366
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.090266 0.057663 1.565 0.117
L1.Burgenland 0.018126 0.032594 0.556 0.578
L1.Kärnten 0.052780 0.016801 3.142 0.002
L1.Niederösterreich 0.181751 0.067710 2.684 0.007
L1.Oberösterreich 0.326925 0.067540 4.840 0.000
L1.Salzburg 0.044036 0.034815 1.265 0.206
L1.Steiermark -0.000214 0.045274 -0.005 0.996
L1.Tirol 0.123914 0.036538 3.391 0.001
L1.Vorarlberg 0.062900 0.032245 1.951 0.051
L1.Wien 0.100566 0.060809 1.654 0.098
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.163059 0.069908 2.332 0.020
L1.Burgenland 0.009108 0.039515 0.230 0.818
L1.Kärnten -0.062510 0.020368 -3.069 0.002
L1.Niederösterreich -0.109877 0.082089 -1.339 0.181
L1.Oberösterreich 0.219964 0.081882 2.686 0.007
L1.Salzburg 0.046352 0.042207 1.098 0.272
L1.Steiermark 0.259689 0.054888 4.731 0.000
L1.Tirol 0.490842 0.044297 11.081 0.000
L1.Vorarlberg 0.065856 0.039092 1.685 0.092
L1.Wien -0.078794 0.073721 -1.069 0.285
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.150307 0.077363 1.943 0.052
L1.Burgenland -0.009383 0.043729 -0.215 0.830
L1.Kärnten 0.064482 0.022540 2.861 0.004
L1.Niederösterreich 0.171670 0.090843 1.890 0.059
L1.Oberösterreich -0.071294 0.090614 -0.787 0.431
L1.Salzburg 0.215393 0.046709 4.611 0.000
L1.Steiermark 0.142202 0.060741 2.341 0.019
L1.Tirol 0.051193 0.049021 1.044 0.296
L1.Vorarlberg 0.145276 0.043261 3.358 0.001
L1.Wien 0.142861 0.081583 1.751 0.080
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.451932 0.043933 10.287 0.000
L1.Burgenland -0.003348 0.024833 -0.135 0.893
L1.Kärnten -0.016456 0.012800 -1.286 0.199
L1.Niederösterreich 0.186264 0.051588 3.611 0.000
L1.Oberösterreich 0.229777 0.051458 4.465 0.000
L1.Salzburg 0.030062 0.026525 1.133 0.257
L1.Steiermark -0.012808 0.034494 -0.371 0.710
L1.Tirol 0.080065 0.027838 2.876 0.004
L1.Vorarlberg 0.050100 0.024567 2.039 0.041
L1.Wien 0.007211 0.046329 0.156 0.876
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.030004 0.090122 0.159404 0.138636 0.073792 0.076743 0.015878 0.208035
Kärnten 0.030004 1.000000 -0.030615 0.132554 0.046484 0.079417 0.450188 -0.075051 0.093920
Niederösterreich 0.090122 -0.030615 1.000000 0.296233 0.109988 0.255933 0.052575 0.146416 0.259091
Oberösterreich 0.159404 0.132554 0.296233 1.000000 0.203149 0.285937 0.159671 0.129176 0.206021
Salzburg 0.138636 0.046484 0.109988 0.203149 1.000000 0.117175 0.067660 0.104059 0.088968
Steiermark 0.073792 0.079417 0.255933 0.285937 0.117175 1.000000 0.128141 0.093733 0.007738
Tirol 0.076743 0.450188 0.052575 0.159671 0.067660 0.128141 1.000000 0.057767 0.136224
Vorarlberg 0.015878 -0.075051 0.146416 0.129176 0.104059 0.093733 0.057767 1.000000 -0.019048
Wien 0.208035 0.093920 0.259091 0.206021 0.088968 0.007738 0.136224 -0.019048 1.000000